package com.tanhua.api.impl.mogo;

import com.tanhua.api.mongo.UserLikeApi;
import com.tanhua.domain.mogo.UserLike;
import com.tanhua.domain.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class UserLikeApiImpl implements UserLikeApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    //查找我喜欢的用户数量
    public long findloveCount(Long id) {
        Query query = new Query(Criteria.where("userId").is(id));
        long count = mongoTemplate.count(query, UserLike.class);//计数
        return count;
    }

    @Override
    //查找我的粉丝数量
    public long findfanCount(Long id) {
        Query query = new Query(Criteria.where("likeUserId").is(id));
        long count = mongoTemplate.count(query, UserLike.class);
        return count;
    }

    @Override
    //todo:查找用户喜欢的人
    public PageBeanVo findUserLikeList(Integer page, Integer pagesize, Long id) {
        return null;
    }

    @Override
    //查找喜欢用户的人
    public PageBeanVo findLikeUserList(Integer page, Integer pagesize, Long id) {
        return null;
    }

    @Override
    public void removeFans(Long fansId, Long userId) {

        Query query = new Query(Criteria.where("likeUserId").is(userId)
                .and("userId").is(fansId));
        mongoTemplate.remove(query,UserLike.class);
    }

    @Override
    public void addUserLike(Long userId, Long loveId) {
        UserLike userLike = new UserLike();
        userLike.setCreated(System.currentTimeMillis());
        userLike.setLikeUserId(userId);
        userLike.setUserId(loveId);

        mongoTemplate.insert(userLike);
    }

}
